﻿using System.Web.Mvc;
using DevFramework.Core.CrossCuttingConcern.ExceptionHandling.Exceptions;
using DevFramework.Core.Web.Enums;

namespace DevFramework.MvcUI.Filters
{
    public class ExceptionFilter : ActionFilterAttribute, IExceptionFilter
    {
        public void OnException(ExceptionContext filterContext)
        {
             
            filterContext.ExceptionHandled = true;

            if (filterContext.Exception is NotificationException)
            {
                filterContext.Result = new ViewResult
                {
                    TempData = new TempDataDictionary
                    {
                        { string.Format("devframework.notifications.{0}", NotifyType.Error),filterContext.Exception.Message }
                    }
                };
            }
            else
            {
                filterContext.Result = new ViewResult()
                {
                    ViewName = "Common/Error",
                    ViewData = new ViewDataDictionary(filterContext.Exception)
                };
            }

        }
    }
}